<?php

/**
 * Class TermCreateAction
 */
class TermCreateAction extends CAction
{
	public $view = 'termCreate';

	public function run($taxonomy_id)
	{
		if (!$taxonomy = Taxonomy::model()->findFromCache($taxonomy_id)) {
			throw new CHttpException(404, '页面没有找到');
		}

		$model = new Term();
		$model->taxonomy = $taxonomy;
		$model->taxonomy_id = $taxonomy_id;

		if (isset($_POST['Term'])) {
			$model->attributes = $_POST['Term'];
			if ($model->save()) {
				Yii::app()->getUser()->setFlash('success', '术语创建成功');
				$url = array('view', 'id' => $taxonomy_id);
				$this->getController()->redirect($url);
			}
		}

		$this->getController()->render($this->view, array('model' => $model));
	}
}